# $Id$
# Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor: Daniel Micay <danielmicay@gmail.com>
# Contributor: Mladen Pejakovic <pejakm@gmail.com>

pkgbase=libxkbcommon
pkgname=(libxkbcommon libxkbcommon-x11)
pkgver=0.7.2
pkgrel=1
pkgdesc="Keymap handling library for toolkits and window systems"
arch=(i686 x86_64)
url="https://xkbcommon.org/"
license=(custom)
depends=(xkeyboard-config glibc)
checkdepends=(xorg-server-xvfb libgl)
makedepends=(libxcb doxygen git graphviz wayland wayland-protocols meson)
_commit=ba9568bdb128f3c5f717b8503439ef6e50a66e97  # tags/xkbcommon-0.7.2^0
source=("git+https://github.com/xkbcommon/libxkbcommon#commit=$_commit")
md5sums=('SKIP')

pkgver() {
  cd $pkgbase
  git describe --tags | sed 's/^xkbcommon-//;s/-/+/g'
}

prepare() {
  mkdir -p build x11/usr/{include/xkbcommon,lib/pkgconfig}
  cd $pkgbase
}

build() {
  cd build
  meson --prefix=/usr --buildtype=release ../$pkgbase
  ninja
}

check() {
  cd build
  xvfb-run -a mesontest
}

package_libxkbcommon() {
  cd build
  DESTDIR="$pkgdir" ninja install
  install -Dm644 ../$pkgbase/LICENSE "$pkgdir/usr/share/licenses/libxkbcommon/LICENSE"

### Split libxkbcommon-x11

  mv "$pkgdir"/usr/lib/*x11* "$srcdir/x11/usr/lib"
  mv "$pkgdir"/usr/lib/pkgconfig/*x11* "$srcdir/x11/usr/lib/pkgconfig"
  mv "$pkgdir"/usr/include/xkbcommon/*x11* "$srcdir/x11/usr/include/xkbcommon"
}

package_libxkbcommon-x11() {
  pkgdesc="Keyboard handling library using XKB data for X11 XCB clients"
  depends=(libxkbcommon libxcb)

  mv x11/* "$pkgdir"

  install -Dm644 $pkgbase/LICENSE "$pkgdir/usr/share/licenses/libxkbcommon-x11/LICENSE"
}
